package com.zyy.game.tianlong.constant;

/**
 * 炸金花扑克牌
 * @author relufi
 * @date 2019/7/30 0030
 */
public class Card {

    /**
     * 方块
     */
    public static final int COLOR_DIAMONDS = 0;
    /**
     * 梅花
     */
    public static final int COLOR_CLUB = 1;
    /**
     * 红桃
     */
    public static final int COLOR_HEARTS = 2;
    /**
     * 黑桃
     */
    public static final int COLOR_SPADE = 3;

    /**
     * <table>
     * <tr> <th>下标</th> <th>代表牌面</th> <th>num</th> </tr>
     * <tr> <td>0-4</td> <td>A</td> <td>14</td> </tr>
     * <tr> <td>4-8</td> <td>2</td> <td>15</td> </tr>
     * <tr> <td>8-12</td> <td>3</td> <td>3</td> </tr>
     * <tr> <td>12-16</td> <td>5</td> <td>5</td> </tr>
     * <tr> <td>...</td> <td>...</td> <td>...</td> </tr>
     * <tr> <td>48-52</td> <td>K</td> <td>13</td> </tr>
     */
    public static final Card[] ALL = new Card[52];

    static {
        for (int i = 0; i < 13; i++) {
            int count = i + 1;
            for (int j = 0; j < 4; j++) {
                ALL[((count * 4) + j) % 52] = new Card(count + 1, j);
            }
        }
    }

    /**
     * 根据牌与颜色获取牌池中的对象
     *
     * @param number 牌面 1(A)-13(K)
     * @param color  颜色
     * @return 牌对象
     */
    public static Card index(int number, int color) {
        return ALL[(number - 1) * 4 + color];
    }

    /**
     * 从3到15
     */
    public final int number;
    /**
     * 颜色
     */
    public final int color;

    private Card(int number, int color) {
        this.number = number;
        this.color = color;
    }

    public int getColor() {
        return color;
    }

    public int getNumber() {
        return number;
    }

    @Override
    public String toString() {
        return "Card{" +
                "number=" + number +
                ", color=" + color +
                '}';
    }

    public boolean compareTo(Card o) {
        return this.number < o.number || (this.number == o.number && (this.color < o.color));
    }
}
